<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>周记实审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="static/css/font.css">
    <link rel="stylesheet" href="static/css/xadmin.css">
    <script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="static/lib/layui/layui.js"></script>
    <script type="text/javascript" src="static/js/xadmin.js"></script>
    <script type="text/javascript" src="static/js/xadminEmp.js"></script>

</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
		<span class="layui-breadcrumb"> <a>周记实</a> <a> <cite>周记实考核</cite></a><a>
            <span style="color:#FF4500;font-size:15px;text-align: center">提示: 本月只能对员工上月的周记实内容进行审核打分,打分完毕切记提交保存。</span> </a>
		</span> <a class="layui-btn layui-btn-small"
                   style="line-height: 1.6em; margin-top: 3px; float: right"
                   href="javascript:location.replace(location.href);" title="刷新"> <i
        class="layui-icon" style="line-height: 30px">ဂ</i></a>
</div>
<div class="x-body" id="container">
    <div class="demoTable">

        &nbsp&nbsp&nbsp 周记实查询：
        <div class="layui-input-inline" style="width: 300px;">
            <select name="chooseMonth" id="chooseMonth" lay-filter="">
                <option value=""></option>
            </select>
        </div>
        &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
        <button class="layui-btn" data-type="reload">查&nbsp;&nbsp;询</button>
        &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp
        &nbsp&nbsp&nbsp
        <a class="layui-btn layui-btn-danger jobDetail"><i
                class="layui-icon layui-icon-key"></i>查看该员工岗位职责</a>


    </div>
    <div style="text-align: center">
        <table id="demo" class="layui-table" lay-filter="demo">
        </table>
        <hr style="border:none;border-top-width:20px;border-top-style:solid;border-top-color:#008B8B;" />
        <table id="demoA" class="layui-table" lay-filter="demoA">
            <!--
            <div class="layui-form-item">
                <label  class="layui-form-label layui-required">审核状态</label>
                <div class="layui-input-block" style="width: 666px;">
                    <select name="xCheckState" lay-filter="xCheckState" id="xCheckState" lay-verify="" autocomplete="off" lay-search>
                        <option value="">请选择审核情况</option>
                        <option value="1">通过</option>
                        <option value="2">不通过</option>
                    </select>
                </div>
            </div>
            -->
            <div class="layui-form-item">
                <label  class="layui-form-label layui-required" >得&nbsp;&nbsp;分</label>
                <div class="layui-input-block" style="width: 666px;">
                    <input class="layui-input" onkeyup="value=zhzs(this.value)" lay-verify="required|number" id="xCheckScore" name="xCheckScore"  value="" maxlength="7">
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label layui-required" >评&nbsp;&nbsp;价</label>
                <div class="layui-input-block" style="width: 666px;">
                    <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="xCheckResult" id="xCheckResult" value="" lay-verify="" autocomplete="off" placeholder="简要描述即可"  class="layui-textarea"></textarea>
                </div>
            </div>
        </table>
    </div>

    <div class="layui-inline">
        <button class="layui-btn layui-btn-bk-red layuiadmin-btn-useradmin site-demo-active" id="batchUnlock">提&nbsp;&nbsp;交</button>
    </div>
</div>
</body>
<style type="text/css">
    .layui-table-cell {
        height: auto;
        line-height: 20px;
        padding: 0 15px;
        position: relative;
        overflow: hidden;
        text-overflow: ellipsis;
        box-sizing: border-box;
        white-space: nowrap;   //nowrap=不换行   normal=正常
    }
</style>

<script>

    window.onload = function () {
        //加载周记实审核结果

        var byEId =decodeURI(getQueryVariable("eId"));//被考核员工的ID
        var byEAccount =decodeURI(getQueryVariable("eAccount"));//被考核员工的工号
        var byDId =decodeURI(getQueryVariable("dId"));//被考核员工的部门ID
        var byPId =decodeURI(getQueryVariable("pId"));//被考核员工的职位ID
        var chooseMonth = document.getElementById("chooseMonth").value;//月份

        //加载月份数下拉搜索框
        var month = $("#chooseMonth");
        $.ajax({
            url: 'employeeWeekCheck/findMonthSelective.do',
            dataType: 'json',
           type: 'post',
            success: function (result) {
                // console.log(result.data);
                //获取上个月的月数
                var last_month = new Date().getMonth();
                last_month = ((last_month == 0) ? (12) : (last_month));
                $.each(result.data,function(index,item){
                    if(item.mId == last_month) {
                        month.append("<option selected value="+item.mId+">"+item.mName+"</option>");
                    } else {
                        month.append("<option value="+item.mId+">"+item.mName+"</option>");
                    }
                })

                layui.form.render('select');  //渲染select

            }
        });


        //加载已审核的信息
        $.ajax({
            url:'employeeWeekCheck/findEmpWeekResultInfoSelective.do',
            dataType:'json',
            data: {
                "byEId": byEId,
                "chooseMonth": chooseMonth
            },
            type:'post',
            success:function(result){
                //console.log("result="+JSON.stringify(result));
                //console.log("result.data="+JSON.stringify(result.data[0]));
                //需要判断一下，该员工是否已经被审核评价，如果是，则直接显示上一次的结果，否则不显示
                if((typeof(result.data[0]) != "undefined")){//
                    $("#xCheckResult").val(result.data[0].xCheckResult);
                    $("#xCheckScore").val(result.data[0].xCheckScore);
                    //$("#xCheckState").val(result.data[0].xCheckState);
                }else{
                    $("#xCheckResult").val("");
                    $("#xCheckScore").val("");
                    //并且提交按钮不可操作
                }
            }
        });

        /**判断一下员工是否已经做了周记实的填写，如果没有，则不允许提交，提交按钮设置不可触发
        $.ajax({
            url:'employeeWeekCheck/findEmpWeekInfoSelective.do',
            dataType:'json',
            data: {"byEId": byEId,"byDId":byDId,"byEAccount":byEAccount},
            type:'post',
            success:function(result){
                //console.log("resultcaocaocoa="+JSON.stringify(result));
                //console.log("resultcaocaocoa.data="+JSON.stringify(result.data[0]));
                //需要判断一下，该员工是否已经被审核评价，如果是，则直接显示上一次的结果，否则不显示
                if((typeof(result.data[0]) == "undefined")){//
                    // 单击之后提交按钮不可选,防止重复提交
                    var DISABLED = 'layui-btn-disabled';
                    // 增加样式
                    $('.site-demo-active').addClass(DISABLED);
                    // 增加属性
                    $('.site-demo-active').attr('disabled', 'disabled');
                    //
                    layer.msg("该员工没有填写上月的周记实内容，请核实");
                }
            }
        });
         **/

    }

    layui.use(['laydate','table'], function(){
        var laydate = layui.laydate
            ,table = layui.table;

        var byEId =decodeURI(getQueryVariable("eId"));//被考核员工的ID
        var byEAccount =decodeURI(getQueryVariable("eAccount"));//被考核员工的工号
        var byDId =decodeURI(getQueryVariable("dId"));//被考核员工的部门ID
        var byPId =decodeURI(getQueryVariable("pId"));//被考核员工的职位ID
        var chooseMonth = document.getElementById("chooseMonth").value;//月份

        //alert("chooseMonth1==="+chooseMonth);

        var cols = [];
        //cols.push({field:'wName', rowspan:2, title: '姓名', width:120, align: 'center',fixed: 'left'});
        //cols.push({field: 'wWeekMonYear', rowspan:2, title: '月份', width:90, align: 'center',fixed: 'left'});
        cols.push({field: 'wWeekMonth', rowspan:2, title: '第几周', width:90, align: 'center',fixed: 'left'});
        //cols.push({field: 'wWeekFirLa', rowspan:2, title: '区间', width:260, align: 'center',fixed: 'left'});
        cols.push({field: 'wWeekInfo', rowspan:2, title: '日常工作', width:420, align: 'left',fixed: 'left'});
        cols.push({field: 'wZdgzInfo', rowspan:2, title: '重点工作', width:420, align: 'left',fixed: 'left'});
        cols.push({field: 'wCxgzInfo', rowspan:2, title: '创新工作', width:230, align: 'left',fixed: 'left'});
        cols.push({field: 'wTempOraryInfo', rowspan:2, title: '其他事项', width:230, align: 'left',fixed: 'left'});
        /**
        cols.push({field:'wFlag',
            templet: function (item) {
                if (item.wFlag == '1') {
                    return "周计划";
                } else if (item.wFlag == '2') {
                    return "临时任务";
                } else {
                    return "";
                }
            },
            rowspan:2, title: '周记实类型', width:150, align: 'center',fixed: 'left'});
        cols.push({field: 'wFinshLivel',
            templet: function (item) {
                if (item.wFinshLivel == '1') {
                    return "已完成";
                } else if (item.wFinshLivel == '2') {
                    return "基本完成";
                } else if (item.wFinshLivel == '3') {
                    return "未完成";
                }else {
                    return "";
                }
            },
            rowspan:2, title: '完成情况', width:150, align: 'center',fixed: 'left'});
         **/

        //第一个实例
        table.render({
            elem: '#demo'
            ,height: 'full'
            ,url: 'employeeWeekCheck/findEmpWeekInfoSelective.do'
            ,page: false
            ,where:{
                "byEId":byEId,
                "byDId":byDId,
                "byEAccount":byEAccount,
                "chooseMonth":chooseMonth
            }
            ,initSort: {field: 'byEAccount', type: 'desc'}
            ,id:'demo'
            ,cols: [cols]
        });

        //下面需要查询一下是不是已经存在打分和评价了，如果存在，直接反写回来，进行修改即可
        //注意了


        var $ = layui.$, active = {

            reload: function () {
                var chooseMonth = $('#chooseMonth').val();
                table.reload('demo', {
                    page: false
                    , where: {
                        chooseMonth: chooseMonth
                    }
                });


                //执行查询，重新刷新界面
                $.ajax({
                    url:'employeeWeekCheck/findEmpWeekResultInfoSelective.do',
                    dataType:'json',
                    data: {
                        "byEId": byEId,
                        "chooseMonth": chooseMonth
                    },
                    type:'post',
                    success:function(result){
                        //console.log("result="+JSON.stringify(result));
                        //console.log("result.data="+JSON.stringify(result.data[0]));
                        //需要判断一下，该员工是否已经被审核评价，如果是，则直接显示上一次的结果，否则不显示
                        if((typeof(result.data[0]) != "undefined")){//
                                $("#xCheckResult").val(result.data[0].xCheckResult);
                                $("#xCheckScore").val(result.data[0].xCheckScore);
                                //$("#xCheckState").val(result.data[0].xCheckState);
                        }else{
                            $("#xCheckResult").val("");
                            $("#xCheckScore").val("");
                        }

                        //如果选择查询的月数和当前月数上个月不相等，那么就不能修改，只能查看，因为只能给上个月的去打分
                        var last_month = new Date().getMonth();
                        last_month = ((last_month == 0) ? (12) : (last_month));
                        var DISABLED = 'layui-btn-disabled';

                        if(chooseMonth != last_month){//除了上个月，其余月份的周纪实，只能查看，不能修改分数
                            $('#batchUnlock').attr("disabled",true);
                            //按钮颜色置灰
                            // 单击之后提交按钮不可选,防止重复提交
                            // 增加样式
                            $('.site-demo-active').addClass(DISABLED);

                        }else{//上个月可以修改分数
                            $('#batchUnlock').attr("disabled",false);
                            //按钮颜色置灰
                            // 单击之后提交按钮不可选,防止重复提交
                            var DISABLED = 'layui-btn-disabled';
                            // 增加样式
                            $('.site-demo-active').removeClass(DISABLED);
                        }
                    }
                });

            },




        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            console.log(type);
            active[type] ? active[type].call(this) : '';
        });
        /**校验是否为空**/
        function checkInputVariable(value)
        {
            if(typeof (value) == 'undefined'){
                return true;
            }else{
                if(value == ''){
                    return true;
                }
            }
        }

        //批量提交  使用封装后的ajax
        $("#batchUnlock").click(function (){
            const list = table.cache['demo'];

            console.log("list="+JSON.stringify(list));

            /**
            var len = list.length;
            for (var i = 0; i < len; i++) {
                var ttv = list[i].fScore

            }
            return layer.msg('caole!', { offset: '70%'});
            **/
            //var xCheckState = document.getElementById("xCheckState").value;//周记实审核状态
            var xCheckScore = document.getElementById("xCheckScore").value;//周记实审核分数
            var xCheckResult = document.getElementById("xCheckResult").value;//周记实审核描述
            var chooseMonth = $('#chooseMonth').val();

            //console.log("xCheckState="+JSON.stringify(xCheckState));
            //console.log("xCheckScore="+JSON.stringify(xCheckScore));
            //console.log("xCheckResult="+JSON.stringify(xCheckResult));
            /**
            var xCheckStateFlag = checkInputVariable(xCheckState);
            if(xCheckStateFlag){
                //return layer.msg("审核状态不能为空!");
                return layer.msg('审核状态不能为空!', { offset: '70%'});
            }
             **/
            var xCheckScoreFlag = checkInputVariable(xCheckScore);
            if(xCheckScoreFlag){
                return layer.msg('审核分数不能为空!', { offset: '70%'});
            }

            //console.log("被考核员工的ID="+JSON.stringify(byEId));

            var reg = new RegExp("^(\\d|[1-9]\\d|100)$");
            if(!reg.test(xCheckScore)) {
                return layer.alert("分数只能是0-100的整数！");
            }

            //临时任务
            var addWeekCheckData = [];
            addWeekCheckData.push({
                xStaffEId:byEId,
                //xCheckState:xCheckState,
                xCheckScore: xCheckScore,
                xCheckResult: xCheckResult
            });

            /**
            var flag = checkInputVariable(list);
            if(flag){
                return layer.msg("请您核实,分数请输入不为空的整数!");
            }
             **/
            //console.log("addWeekCheckDataList="+JSON.stringify(addWeekCheckData));
            //console.log("qTargetid="+gTargetid);
            $.ajax({
                type: 'post',
                url: 'employeeWeekCheck/addWeekCheckInfo.do',
                data: "list="+JSON.stringify(addWeekCheckData)+"&byEId="+byEId+"&chooseMonth="+chooseMonth,//将json数据转化为字符串
                dataType: 'json',
                success: function (result) {
                    if (result.code == 100) {
                        layer.alert("审核成功", {offset: '70%',title: "审核信息"},
                            function () {
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            }
                        )

                    } else {
                        layer.msg(result.message);
                    }
                },
            });

        });


        $(".jobDetail").click(function (){
            xx_admin_show('员工岗位工作任务详情描述',
                'toPage.do?url=employee/week/employeeJob-list.html?byEAccount='+byEAccount
                , 888,500);
        });


    });
    //考核输入项检查
    function checkInputVariable(list,gTargetid)
    {
        var len = list.length;
        for(var i=0; i<len; i++){

            var value = list[i].qTargetscore;
            if(typeof (value) == 'undefined'){
                return true;
            }else{
                if(value == ''){
                    return true;
                }else{
                    var regPos = /^\d+(\.\d+)?$/; //非负浮点数
                    var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
                    if((!regPos.test(value)) && !regNeg.test(value) && !value.match("[1-9]+")){
                        return true;
                    }
                }
            }
            delete list[i].LAY_TABLE_INDEX;
        }
    }

    //获取父页面请求url传过来的参数
    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var index = query.indexOf("?");
        query = query.substr(index+1,query.length);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){
                console.log(pair[1]);
                return pair[1];
            }
        }
        return false;
    }

    //考核输入项检查
    function checkInputVariable(list,gTargetid)
    {
        var len = list.length;
        for(var i=0; i<len; i++){

            var value = list[i].qTargetscore;
            if(typeof (value) == 'undefined'){
                return true;
            }else{
                if(value == ''){
                    return true;
                }else{
                    var regPos = /^\d+(\.\d+)?$/; //非负浮点数
                    var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
                    if((!regPos.test(value)) && !regNeg.test(value) && !value.match("[1-9]+")){
                        return true;
                    }
                }
            }
            delete list[i].LAY_TABLE_INDEX;
        }
    }

    /*自定义处理数字*/
    function zhzs(value){

        value = value.replace(/[^\d]/g,'');

        if(''!=value){
            value = parseInt(value);
        }
        return value;
    }
</script>
</html>
